<?php

require_once 'BaseMapper.php';

class Application_Model_PorcinoMapper extends BaseMapper
{

    public function __construct()
    {
        parent::setDbTable(new Application_Model_DbTable_Porcino());
        parent::setExtendedModel(new Application_Model_Porcino());
    }

    public function fetchHembrasByGranja($id_granja)
    {
        //TODO filter to only get the 'hembras'
        $table = Zend_Db_Table::getDefaultAdapter();
        $select = $table->select()
            ->from(array('pg' => 'porcino_has_granja'))
            ->joinInner(array('p' => 'porcino'), "pg.porcino_id = p.id", array('*'))
            ->where("pg.granja_id=" . $id_granja . " AND p.sexo='h'" );

        $resultSet = $table->fetchAll($select);

        $entries = array();
        foreach ($resultSet as $row) {
            $mapped = $this->map($row);
            $entries[] = $mapped;
        }
        return $entries;
    }
    public function fetchVerradosByGranja($id_granja)
    {
        //TODO filter to only get the 'hembras'
        $table = Zend_Db_Table::getDefaultAdapter();
        $select = $table->select()
            ->from(array('pg' => 'porcino_has_granja'))
            ->joinInner(array('p' => 'porcino'), "pg.porcino_id = p.id", array('*'))
            ->where("pg.granja_id=" . $id_granja . " AND p.sexo='m'" );

        $resultSet = $table->fetchAll($select);

        $entries = array();
        foreach ($resultSet as $row) {
            $mapped = $this->map($row);
            $entries[] = $mapped;
        }
        return $entries;
    }
}

